package com.kexio.common.constant;

/**
 * 缓存相关常量
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public final class CacheConstants {
    
    private CacheConstants() {
        throw new UnsupportedOperationException("This is a constants class and cannot be instantiated");
    }
    
    // ==================== 缓存名称 ====================
    
    /**
     * 用户缓存
     */
    public static final String USER_CACHE = "user";
    
    /**
     * 角色缓存
     */
    public static final String ROLE_CACHE = "role";
    
    /**
     * 权限缓存
     */
    public static final String PERMISSION_CACHE = "permission";
    
    /**
     * 菜单缓存
     */
    public static final String MENU_CACHE = "menu";
    
    /**
     * 字典缓存
     */
    public static final String DICT_CACHE = "dict";
    
    /**
     * 配置缓存
     */
    public static final String CONFIG_CACHE = "config";
    
    /**
     * 功能开关缓存
     */
    public static final String FEATURE_TOGGLE_CACHE = "feature_toggle";
    
    /**
     * 租户缓存
     */
    public static final String TENANT_CACHE = "tenant";
    
    // ==================== 缓存键前缀 ====================
    
    /**
     * 缓存键分隔符
     */
    public static final String CACHE_KEY_SEPARATOR = ":";
    
    /**
     * 缓存键前缀
     */
    public static final String CACHE_KEY_PREFIX = "kexio";
    
    /**
     * 用户缓存键前缀
     */
    public static final String USER_KEY_PREFIX = CACHE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "user";
    
    /**
     * 角色缓存键前缀
     */
    public static final String ROLE_KEY_PREFIX = CACHE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "role";
    
    /**
     * 权限缓存键前缀
     */
    public static final String PERMISSION_KEY_PREFIX = CACHE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "permission";
    
    /**
     * 菜单缓存键前缀
     */
    public static final String MENU_KEY_PREFIX = CACHE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "menu";
    
    /**
     * 字典缓存键前缀
     */
    public static final String DICT_KEY_PREFIX = CACHE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "dict";
    
    /**
     * 配置缓存键前缀
     */
    public static final String CONFIG_KEY_PREFIX = CACHE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "config";
    
    /**
     * 功能开关缓存键前缀
     */
    public static final String FEATURE_TOGGLE_KEY_PREFIX = CACHE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "feature";
    
    /**
     * 租户缓存键前缀
     */
    public static final String TENANT_KEY_PREFIX = CACHE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "tenant";
    
    /**
     * 会话缓存键前缀
     */
    public static final String SESSION_KEY_PREFIX = CACHE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "session";
    
    /**
     * 验证码缓存键前缀
     */
    public static final String CAPTCHA_KEY_PREFIX = CACHE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "captcha";
    
    // ==================== 具体缓存键模板 ====================
    
    /**
     * 用户信息缓存键: kexio:user:info:{userId}
     */
    public static final String USER_INFO_KEY = USER_KEY_PREFIX + CACHE_KEY_SEPARATOR + "info" + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * 用户权限缓存键: kexio:user:permissions:{userId}
     */
    public static final String USER_PERMISSIONS_KEY = USER_KEY_PREFIX + CACHE_KEY_SEPARATOR + "permissions" + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * 用户角色缓存键: kexio:user:roles:{userId}
     */
    public static final String USER_ROLES_KEY = USER_KEY_PREFIX + CACHE_KEY_SEPARATOR + "roles" + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * 用户菜单缓存键: kexio:user:menus:{userId}
     */
    public static final String USER_MENUS_KEY = USER_KEY_PREFIX + CACHE_KEY_SEPARATOR + "menus" + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * 角色权限缓存键: kexio:role:permissions:{roleId}
     */
    public static final String ROLE_PERMISSIONS_KEY = ROLE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "permissions" + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * 权限树缓存键: kexio:permission:tree
     */
    public static final String PERMISSION_TREE_KEY = PERMISSION_KEY_PREFIX + CACHE_KEY_SEPARATOR + "tree";
    
    /**
     * 菜单树缓存键: kexio:menu:tree:{userId}
     */
    public static final String MENU_TREE_KEY = MENU_KEY_PREFIX + CACHE_KEY_SEPARATOR + "tree" + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * 字典项缓存键: kexio:dict:items:{dictType}
     */
    public static final String DICT_ITEMS_KEY = DICT_KEY_PREFIX + CACHE_KEY_SEPARATOR + "items" + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * 系统配置缓存键: kexio:config:{configKey}
     */
    public static final String SYSTEM_CONFIG_KEY = CONFIG_KEY_PREFIX + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * 功能开关缓存键: kexio:feature:{featureName}
     */
    public static final String FEATURE_TOGGLE_KEY = FEATURE_TOGGLE_KEY_PREFIX + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * 租户信息缓存键: kexio:tenant:info:{tenantId}
     */
    public static final String TENANT_INFO_KEY = TENANT_KEY_PREFIX + CACHE_KEY_SEPARATOR + "info" + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * JWT Token黑名单缓存键: kexio:session:blacklist:{jti}
     */
    public static final String TOKEN_BLACKLIST_KEY = SESSION_KEY_PREFIX + CACHE_KEY_SEPARATOR + "blacklist" + CACHE_KEY_SEPARATOR + "%s";
    
    /**
     * 验证码缓存键: kexio:captcha:{sessionId}
     */
    public static final String CAPTCHA_CODE_KEY = CAPTCHA_KEY_PREFIX + CACHE_KEY_SEPARATOR + "%s";
    
    // ==================== 缓存过期时间(秒) ====================
    
    /**
     * 用户信息缓存过期时间 - 30分钟
     */
    public static final int USER_INFO_TTL = 1800;
    
    /**
     * 用户权限缓存过期时间 - 1小时
     */
    public static final int USER_PERMISSIONS_TTL = 3600;
    
    /**
     * 权限树缓存过期时间 - 2小时
     */
    public static final int PERMISSION_TREE_TTL = 7200;
    
    /**
     * 菜单树缓存过期时间 - 1小时
     */
    public static final int MENU_TREE_TTL = 3600;
    
    /**
     * 字典缓存过期时间 - 1天
     */
    public static final int DICT_TTL = 86400;
    
    /**
     * 配置缓存过期时间 - 1小时
     */
    public static final int CONFIG_TTL = 3600;
    
    /**
     * 功能开关缓存过期时间 - 30分钟
     */
    public static final int FEATURE_TOGGLE_TTL = 1800;
    
    /**
     * 租户信息缓存过期时间 - 1小时
     */
    public static final int TENANT_INFO_TTL = 3600;
    
    /**
     * Token黑名单缓存过期时间 - 7天
     */
    public static final int TOKEN_BLACKLIST_TTL = 604800;
    
    /**
     * 验证码缓存过期时间 - 5分钟
     */
    public static final int CAPTCHA_TTL = 300;
    
    // ==================== 工具方法 ====================
    
    /**
     * 构建缓存键
     */
    public static String buildKey(String template, Object... params) {
        if (params == null || params.length == 0) {
            return template;
        }
        return String.format(template, params);
    }
    
    /**
     * 构建用户信息缓存键
     */
    public static String buildUserInfoKey(Long userId) {
        return buildKey(USER_INFO_KEY, userId);
    }
    
    /**
     * 构建用户权限缓存键
     */
    public static String buildUserPermissionsKey(Long userId) {
        return buildKey(USER_PERMISSIONS_KEY, userId);
    }
    
    /**
     * 构建用户角色缓存键
     */
    public static String buildUserRolesKey(Long userId) {
        return buildKey(USER_ROLES_KEY, userId);
    }
    
    /**
     * 构建系统配置缓存键
     */
    public static String buildConfigKey(String configKey) {
        return buildKey(SYSTEM_CONFIG_KEY, configKey);
    }
    
    /**
     * 构建功能开关缓存键
     */
    public static String buildFeatureToggleKey(String featureName) {
        return buildKey(FEATURE_TOGGLE_KEY, featureName);
    }
}
